<?php
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
?>
<script type="text/javascript">
    var searchProperty = "<?php echo $searchProperty;?>";
    var searchField = "<?php echo $searchField;?>";
    var searchText = "<?php echo $searchText;?>";

    function checkAll(){
       var checkall=document.getElementsByName('check_all');
       for(var i=0;i<checkall.length;i++)
       {
          checkall[i].checked=true;
       }
    }
    function checkInvert(){
       var checkall=document.getElementsByName('check_all');
       for(var i=0;i<checkall.length;i++)
       {
           if(checkall[i].checked)
                checkall[i].checked=false;
           else
                checkall[i].checked=true;
       }
    }
    function editInfo(content) {
        location = "<?php echo url_for("sysUser/edit?contentEdit=1&content=");  ?>" + content;
    }
    function actionFun(content, actionType) {
        var confirmResult = false;
        //if(content == null && actionType)
        switch (actionType) {
            case "unaccess":
                confirmResult = confirm('确定要删除？');
                break;
            case "access":
                confirmResult = confirm('确定要取消删除吗？');
                break;
        }
        if (actionType == "search")
            confirmResult = true;
        if (confirmResult) {
            if (1 == content && actionType != "search") {
                var checkall = document.getElementsByName('check_all');
                content = "";
                for (var i = 0; i < checkall.length; i++) {
                    if (checkall[i].checked)
                        content += checkall[i].value + " ";
                }
            }
            if (actionType == "search") {
                if ($("#sSearchProperty").val() != "none")
                    content += "&searchProperty=" + $("#sSearchProperty").val();
                if ($("#sSearchField").val() != "none")
                    content += "&searchField=" + $("#sSearchField").val();
                var searchCondition = $.trim($("#txtSearch").val());
                if (searchCondition != "") {
                    content += "&searchText=" + searchCondition;
                }
            }
            var nowurl=window.location;
            window.location = "<?php echo url_for("sysUser/index?submitType=");?>" + actionType + "&content=" + content;
            switch (actionType) {
                case "access":
                case "unaccess":
                    window.location=nowurl;
                    break;
            }
        }
    }

    $(document).ready(function() {
        if (searchProperty != "")
            $("#sSearchProperty").val(searchProperty);
        if (searchField != "")
            $("#sSearchField").val(searchField);
        $("#txtSearch").val(searchText);
    });
</script>
<table width="100%" border="0" cellspacing="0" cellpadding="0" style="padding-right:10px;">
    <tr>
        <td style="height:30px;">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td>位置：用户管理 -> 系统用户</td>
                    <td></td>
                </tr>
            </table>
        </td>
    </tr>
    <tr>
        <td style="height:30px;">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td>
                        <input id="add" type="button" onclick="window.location='<?php echo url_for("sysUser/add?contentEdit=1");  ?>';" value="添加系统用户" />
<input id="del" type="button" onclick="actionFun(1,'unaccess');" value="删除" /></td>
                    <td align="right">搜索：
                        <select name="sSearchProperty" id="sSearchProperty" onchange="actionFun(null,'search')">
                            <option value="none">不限属性</option>
                            <option value="access">在线用户</option>
                            <option value="unaccess">已经删除</option>
                        </select>
                        <input name="txtSearch" type="text" id="txtSearch"/>
                        <select name="sSearchField" id="sSearchField" onchange="actionFun(null,'search')">
                            <option value="none">不限字段</option>
                            <option value="uid">用户ID</option>
                            <option value="uname">用户名</option>
                            <option value="unick">昵称</option>
                        </select>
                        <input name="btnSearch" type="button" id="btnSearch" value="搜索"
                               onclick="actionFun(null,'search')"/></td>
                </tr>
            </table>

        </td>
    </tr>
    <tr>
        <td>
<?php
        //echo $aaa;
           echo "<table cellspacing='0' cellpadding='4' border='1' style=\"width:100%;color:#333333;border-collapse:collapse;\">
           <tr style=\"color:White;background-color:#5D7B9D;font-weight:bold;height:25px;\">
           <td style=\"width:50px;\" align=\"center\">ID</td><td style=\"width:30px;\" align=\"center\">选择</td>
           <td align=\"center\" style='width:200px;'>用户名</td>
           <td style=\"width:100px;\" align=\"center\">昵称</td>
           <td style=\"width:80px;\" align=\"center\">最近登录IP</td>
           <td style=\"width:100px;\" align=\"center\">最近登录时间</td>
           <td style=\"width:70px;\" align=\"center\">操作</td></tr>";
//<table><tr><td>ID</td><td>选择</td><td>用户名</td><td>昵称</td><td>真实姓名</td><td>注册时间</td><td>操作</td></tr>
           $users = @$pages->getResults();
           $i=0;
           foreach($users as $row=>$user)
           {
               if($i%2 == 0)
                   $trStyle = "style=\"color:#333333;background-color:#F7F6F3;height:30px;\"";
               else
                   $trStyle = "style=\"color:#284775;background-color:White;height:30px;\"";
               echo "<tr ".$trStyle."><td>".$user->getSystemUserId()."</td><td align=\"center\"><input type='checkbox' name='check_all' value='"
                       .$user->getSystemUserId()."' /></td><td><a href='javascript:editInfo(".$user->getSystemUserId().")'>".$user->getName()."</a><td>".$user->getNickname()."</td><td>".$user->getLoginIp()
                       ."</td><td>".(""==$user->getLastLoginTime()?"尚未登录":date('Y-m-d H:m:s',strtotime($user->getLastLoginTime()))) ."</td><td><image border='0' title='修改' src='/sfDoctrinePlugin/images/edit.png' style='cursor:pointer;' onclick='editInfo(".$user->getSystemUserId().")'/>"
                       ."<img border='0' title='删除' src='/sfDoctrinePlugin/images/delete.png'onclick='actionFun(" . $user->getSystemUserId() . ",\"unaccess\");' style='cursor:pointer;' /></td></tr>";
               $i++;
           }
           echo "</table>";
           $numPages= $pages->getLastPage();
           $CurrentPageID=$pages->getPage();
             if(@$pages->haveToPaginate())
			{
				$str=$CurrentPageID-6;
				$end=$CurrentPageID+5;
				if($str<0)
					$str=0;
				if($end>$numPages)
					$end=$numPages;
                $catalogStr = "";
            $ords=0;
            switch($searchProperty)
            {
                case "access":
                case "unaccess":
                    $catalogStr.="&searchProperty=" . $searchProperty;
                    $ords++;
                    break;
            }
            switch($searchField)
            {
                case "uid":
                case "uname":
                case "unick":
                $catalogStr.="&searchField=" . $searchField;
                if(!empty($searchText))
                    $catalogStr.="&searchText=" . $searchText;
                $ords++;
                break;
            }
            if($ords>0)
                $catalogStr .="&submitType=search";
				echo "<div class='page_list'>";
				if($CurrentPageID>1)
					echo link_to("首页","sysUser/index?currentPage=1".$catalogStr,"").link_to("上一页","sysUser/index?currentPage=".($CurrentPageID-1).$catalogStr,"");
				 for($i=$str;$i<$end;$i++)
				 {
					if($i==($CurrentPageID-1)){
					echo "<a class='now02' href='#'>".($i+1)."</a>";}
					else{
					    echo link_to(($i+1),"sysUser/index?currentPage=".($i+1).$catalogStr,"");
                    }
				 }
				 if($CurrentPageID<$numPages)
				    echo link_to("下一页","sysUser/index?currentPage=".($CurrentPageID+1).$catalogStr,"").link_to("末页","sysUser/index?currentPage=".$numPages.$catalogStr,"");
				 echo "</div>";
			}
?>
            </td>
    </tr>
    <tr>
        <td valign="middle" style="height:30px;">
            <input type='button' onclick='checkAll();' value='全选'/> <input type='button' onclick='checkInvert();'
                                                                           value='反选'/> <input type='button'
                                                                                               onclick='actionFun(1,"access");'
                                                                                               value='取消删除'/> <input
                type='button' onclick='actionFun(1,"unaccess");' value='删除'/></td>
    </tr>
    <tr>
        <td>

        </td>
    </tr>
</table>
